import {Row,Col,Button,Modal} from 'antd';
import { WeaBrowser,WeaNewScroll,WeaRichText,WeaTools} from 'ecCom';
import { inject, observer } from 'mobx-react';
import {WeaLocaleProvider,WeaAvatar} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;
const confirm = Modal.confirm;


let _this = null;
@inject('createWorkPlanStore')
@observer
class TabDiscuss extends React.Component {
    constructor(props) {
        super(props);
        _this = this;
        this.state = {
            title: props.title ? props.title : getLabel(383345,'请输入标题'),
            BrowserList:{'create':{
                                  remark:''
                        },
                        datas:[],
            },
            secretLevel:props.secretLevel,
            toolChange: false
        }
    }
    shouldComponentUpdate(nextProps, nextState) {
        //组件渲染控制
        //return this.props.title !== nextProps.title
        return true;
    }
    componentDidMount() {
      const  {exchangeList} = this.props;
      let BrowserList = {};
      exchangeList && exchangeList.datas && exchangeList.datas.forEach((element,index)=>{
              if(BrowserList[element['id']]==undefined){
                  BrowserList[element['id']] = {};
              }
              BrowserList[element['id']].remark = element.remark
              BrowserList[element['id']].docids = element.docids
              BrowserList[element['id']].projectids = element.projectids
              BrowserList[element['id']].relatedcus = element.relatedcus
              BrowserList[element['id']].relateddoc = element.relateddoc
              BrowserList[element['id']].relatedwf = element.relatedwf
      })
              BrowserList.datas = exchangeList.datas
              BrowserList.docids = exchangeList.docids
              BrowserList.projectids = exchangeList.projectids
              BrowserList.relatedcus = exchangeList.relatedcus
              BrowserList.relateddoc = exchangeList.relateddoc
              BrowserList.relatedwf = exchangeList.relatedwf
      this.setState({BrowserList:BrowserList})

    }
    componentWillReceiveProps(nextProps) {
        // if (this.props.showGroup !== nextProps.showGroup) {
        //     this.setState({showGroup: nextProps.showGroup});
        // }
        const  {exchangeList} = nextProps;
        let BrowserList = {};
        exchangeList && exchangeList.datas &&  exchangeList.datas.forEach((element,index)=>{
                if(BrowserList[element['id']]==undefined){
                    BrowserList[element['id']] = {};
                }
                BrowserList[element['id']].remark = element.remark
                BrowserList[element['id']].docids = element.docids
                BrowserList[element['id']].projectids = element.projectids
                BrowserList[element['id']].relatedcus = element.relatedcus
                BrowserList[element['id']].relateddoc = element.relateddoc
                BrowserList[element['id']].relatedwf = element.relatedwf
        })
                BrowserList.datas = exchangeList.datas;
                BrowserList.docids = exchangeList.docids
                BrowserList.projectids = exchangeList.projectids
                BrowserList.relatedcus = exchangeList.relatedcus
                BrowserList.relateddoc = exchangeList.relateddoc
                BrowserList.relatedwf = exchangeList.relatedwf


        this.setState({BrowserList:BrowserList})
    }



    render() {
        const {title,BrowserList} = this.state;
        let {isPro}= this.props.createWorkPlanStore;
        const  {workPlanId} = this.props;
        let exchangeListDatas = BrowserList ? BrowserList.datas:[];
        let bottomBarConfig = [];
        let extentsConfig = [];
        const mirror =  {
            Document: {type: 37, name: getLabel(22243,'文档'), icon: 'icon-blog-Document'},
            Flow: {type: 152, name: getLabel(30045,'流程'), icon: 'icon-blog-Process'},
            Customer: {type: 18, name: getLabel(136,'客户'), icon: 'icon-blog-Personnel'},
            Project: {type: 135, name: getLabel(101,'项目'), icon: 'icon-blog-Project'},
            Task: {type: 'prjtsk', name: getLabel(1332,'任务'), icon: 'icon-blog-Task'},
        }
        let objDocument = {
                    name: 'Browser',
                    show: <div className="wea-cb-item">
                        <span className={`wea-cbi-icon ${mirror['Document'].icon}`}/>
                        <span className="wea-cbi-text">{mirror['Document'].name}</span>
                    </div>,
                    type: mirror['Document'].type,
                    title: mirror['Document'].name,
                    completeParams:{secretLevel:this.state.secretLevel},
                    dataParams:{secretLevel:this.state.secretLevel}
                };
        let objFlow = {
                    name: 'Browser',
                    show: <div className="wea-cb-item">
                        <span className={`wea-cbi-icon ${mirror['Flow'].icon}`}/>
                        <span className="wea-cbi-text">{mirror['Flow'].name}</span>
                    </div>,
                    type: mirror['Flow'].type,
                    title: mirror['Flow'].name,
                    completeParams:{secretLevel:this.state.secretLevel},
                    dataParams:{secretLevel:this.state.secretLevel}
                };
        let objCustomer = {
                    name: 'Browser',
                    show: <div className="wea-cb-item">
                        <span className={`wea-cbi-icon ${mirror['Customer'].icon}`}/>
                        <span className="wea-cbi-text">{mirror['Customer'].name}</span>
                    </div>,
                    type: mirror['Customer'].type,
                    title: mirror['Customer'].name,
                };

        let objProject = {
                    name: 'Browser',
                    show: <div className="wea-cb-item">
                        <span className={`wea-cbi-icon ${mirror['Project'].icon}`}/>
                        <span className="wea-cbi-text">{mirror['Project'].name}</span>
                    </div>,
                    type: mirror['Project'].type,
                    title: mirror['Project'].name,
                };
        let objTask = {
                    name: 'Browser',
                    show: <div className="wea-cb-item">
                        <span className={`wea-cbi-icon ${mirror['Task'].icon}`}/>
                        <span className="wea-cbi-text">{mirror['Task'].name}</span>
                    </div>,
                    type: mirror['Task'].type,
                    title: mirror['Task'].name,
                };

                BrowserList.docids && bottomBarConfig.push(objDocument);//相关文档
                BrowserList.relatedwf && bottomBarConfig.push(objFlow);//相关流程
                BrowserList.relatedcus && bottomBarConfig.push(objCustomer);//相关客户
                BrowserList.projectids && bottomBarConfig.push(objProject);//相关项目
                BrowserList.relateddoc && bottomBarConfig.push({
                    name: 'Upload',
                    show: <div className="wea-cb-item">
                        <span className='wea-cbi-icon icon-blog-Enclosure'/>
                        <span className="wea-cbi-text">{getLabel(156,'附件')}</span>
                    </div>,
                    uploadId: 'meeting_edit',
                    uploadUrl: `${BrowserList.relateddoc.uploadUrl}${BrowserList.relateddoc.uploadUrl.indexOf("category")<0?("?category="+BrowserList.relateddoc.category):""}`,
                    category: BrowserList.relateddoc.category,
                    maxUploadSize: BrowserList.relateddoc.maxSize,
					mixUploadSize: BrowserList.relateddoc.minSize,
                    style: {display: "inline-block", padding: 0}
                })
                //相关附件--relateddoc
        let browserParam = {
                        hasAddBtn:false,
                        hasAdvanceSerach:true,
                        idSeparator:",",
                        isAutoComplete:1,
                        isDetail:0,
                        isMultCheckbox:false,
                        isSingle:true,
                        linkUrl:"/hrm/resource/HrmResource.jsp?id=",
                        pageSize:10,
                        quickSearchName:"",
                        title:`${getLabel(179,'人力资源')}`,
                        type:"1",
                        viewAttr:1,
                     };  
        return (
            <div className="preview-tabDiscuss"
                style = {{backgroundColor:'#f7f7f7',padding:'16px 16px 0 16px',}}
            >
                
                    {
                        Array.isArray(BrowserList.datas) && BrowserList.datas.map((element,index)=>{
                          extentsConfig = [{
                            name: "At",
                            data: this.props.exchangeList.atList,
                            position:'first',
                            pushMessageParams: {
                              title: this.props.exchangeList.workplanName,
                              context: `${this.props.exchangeList.username}：<p>${this.state.BrowserList[element.id].remark}`,
                              groupCode: "2211",
                              linkurl: `/spa/workplan/static/index.html#/main/wp/workPlanCreateSingle?workPlanId=${workPlanId}&activeKey=7`,
                              linkMobileUrl: `/spa/workplan/static4mobile/index.html#/detail/discussData?workplanId=${workPlanId}&isDiscuss=1`,
                            }
                          }];
                            let replaceDatas = [];
                            replaceDatas.push(element.creater);
                            let WeaRichTextValue = element.remark ? element.remark : '';
                            let baseParams = {
                                '37':'docids',
                                '152':'relatedwf',
                                '18':'relatedcus',
                                '135':'projectids',
                                'prjtsk':'relatedprj',
                            }
                            element['id'] == BrowserList[element['id']]
                            let newbottomBarConfig = bottomBarConfig.map((_element,_index)=>{
                                _element['memorise'] = true
                                for(let key in BrowserList){
                                    if(key == element['id']){
                                        return {..._element,replaceDatas:BrowserList[element['id']][baseParams[_element.type]]}
                                    }
                                }
                                return _element
                            })
                            newbottomBarConfig.push({
                                name: 'Component', 
                                show: <span>
                                            <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@fnfzhm@submit`} key="submit"  type="primary" style={{display:'inline-block',borderRadius:'3px'}}  onClick={() => this.dosubmit(element.id)} ><span className="icon-coms-Release" style={{paddingRight:'7px'}}/>{getLabel(615,'提交')}</Button>
                                            <Button ecId={`${this && this.props && this.props.ecId || ''}_Button@tl4ylt@cancel`} key="cancel"  type="primary" style={{display:element.id!='create'?'inline-block':'none',marginLeft:'5px',borderRadius:'3px'}}  onClick={() => {this.docancel(index)}} >{getLabel(201,'取消')}</Button>
                                        </span>
                            })

                            
                            let show = element.isEdit == true?
                            <WeaNewScroll ecId={`${this && this.props && this.props.ecId || ''}_WeaNewScroll@dtmf5w@discuss`} height='252px'>
                                <div style = {{backgroundColor:'#ffffff',height:'242px',marginBottom:'10px'}}>
                                    <WeaRichText ecId={`${this && this.props && this.props.ecId || ''}_WeaRichText@j50qsz@discuss`} 
                                        id={`${element.id}_discuss`}
                                        ref={ `${element.id}_discuss`}
                                        value={this.state.BrowserList[element.id].remark}
                                        ckConfig={{
                                            toolbar:[
                                                { name: 'document', items: [ 'Source'] },
                                                { name: 'paragraph', items: [ 'JustifyLeft', 'JustifyCenter', 'JustifyRight', '-', 'NumberedList', 'BulletedList' ] },
                                                { name: 'styles', items: [ 'Format', 'Font', 'FontSize' ] },
                                                { name: 'colors', items: [ 'TextColor' ] },
                                                { name: 'basicstyles', items: [ 'Bold', 'Italic', 'Underline', 'Strike', ] },
                                                { name: 'insert', items: [ 'Image', 'Table', 'Smiley'] }
                                            ],
                                            extraPlugins: 'autogrow',
                                            height: 150,
                                            autoGrow_minHeight:150,
                                            autoGrow_maxHeight: 160,
                                            removePlugins: 'resize',
                                            uploadUrl: '/api/doc/upload/uploadFile?model=reply',
                                        }}
                                        extentsConfig={extentsConfig}
                                        bottomBarConfig={newbottomBarConfig}
                                        onChange={(text)=>this.onChange(element.id,text)}
                                        onStatusChange={s => {}}
                                        onToolsChange={(name,ids,list,type)=>this.transfStr(name,ids,list,type,element.id)}
                                    />
                                </div>
                            </WeaNewScroll>
                            :   <div style = {{borderBottom:'1px solid #E2E2E2',padding:"10px 10px 0 10px" ,backgroundColor:'#ffffff'}}>
                                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@9izvas@discuss`} >
                                        {/*<WeaNewScroll height = "110px">*/}
                                            <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@poduhw@discuss`} span = {2}>
                                                {
                                                    element.creater&&element.creater.id ? <span style={{height:'40px',width:'40px',borderRadius:'20px',display:'inline-block'}}>
                                                        <WeaAvatar ecId={`${this && this.props && this.props.ecId || ''}_WeaAvatar@q7nam8`} // url加载失败显示默认处理
                                                            userId={element.creater.id}
                                                        />
                                                    </span>
                                                    :
                                                    <img src={`${element.creater.imgurl}`} style={{height:'40px',width:'40px',borderRadius:'20px'}} />
                                                }
                                            </Col>
                                            <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@g5pbkm@discuss`} span = {22}>
                                                
                                                <div style = {{marginBottom:'20px'}}>
                                                    <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@97amyd@discuss`} {...browserParam} replaceDatas={replaceDatas} />
                                                </div>
                                                
                                                {
                                                    <div className="discuss-remark-content" dangerouslySetInnerHTML={{__html:element.remark}} style={{minHeight:'50px',overflow: 'auto'}} />
                                                }
                                                {
                                                    element.projectids.length>0?
                                                    element.projectids.map((e,_index)=>{//相关项目
                                                        return <div>
                                                            <span className="icon-blog-Project" style={{paddingRight:'5px'}}/>
                                                            <a href='javascript:void(0)'  linkid={e.id} linkType='workflow' 
                                                            onClick={()=> openWorkplanAppLink('project',e.id,workPlanId,isPro)} ondblclick={()=> false}  
                                                            unselectable='off' contenteditable='false' style={{cursor:'pointer',textDecoration:'underline !important',marginRight:'8px'}}>{e.name} </a>
                                                        </div>
                                                    }):''
                                                }
                                                {
                                                    element.relatedcus.length>0?
                                                    element.relatedcus.map((e,_index)=>{//客户
                                                        return <div>
                                                            <span className="icon-blog-Personnel" style={{paddingRight:'5px'}}/>
                                                            <a href='javascript:void(0)'  linkid={e.id} linkType='workflow' 
                                                            onClick={()=> openWorkplanAppLink('crm',e.id,workPlanId,isPro)} ondblclick={()=> false}  
                                                            unselectable='off' contenteditable='false' style={{cursor:'pointer',textDecoration:'underline !important',marginRight:'8px'}}>{e.name} </a>
                                                        </div>
                                                    }):''
                                                }
                                                {
                                                    element.relateddoc.length>0?
                                                    element.relateddoc.map((e,_index)=>{//修改成附件
                                                        if(e.showLoad){
                                                            return <div>
                                                                <span className="icon-blog-Enclosure" style={{paddingRight:'5px'}}/>
                                                                <a onClick={()=>openWorkplanDiscussDoc(this,e.fileid,workPlanId,isPro)} href='javascript:void(0);'
                                                                unselectable='off' contenteditable='false' style={{cursor:'pointer',textDecoration:'underline !important',marginRight:'8px'}}>{e.filename}</a>
                                                                <a unselectable='off' contenteditable='false' href={e.loadlink} target='_blank'
                                                                 style={{cursor:'pointer',textDecoration:'underline !important',marginRight:'8px'}}>{getLabel(258,"下载")}({e.filesize})</a>
                                                            </div>
                                                        }else{
                                                            return <div>
                                                                <span className="icon-blog-Enclosure" style={{paddingRight:'5px'}}/>
                                                                <a onClick={()=>openWorkplanDiscussDoc(this,e.fileid,workPlanId,isPro)} href='javascript:void(0);'
                                                                unselectable='off' contenteditable='false' style={{cursor:'pointer',textDecoration:'underline !important',marginRight:'8px'}}>{e.filename}</a>
                                                            </div>
                                                        }
                                                    }):''
                                                }
                                                
                                                {
                                                    element.relatedwf.length>0?
                                                    element.relatedwf.map((e,_index)=>{//流程
                                                        return <div>
                                                            <span className="icon-blog-Process" style={{paddingRight:'5px'}}/>
                                                            <a href='javascript:void(0)'  linkid={e.id} linkType='workflow' 
                                                            onClick={()=> openWorkplanAppLink('workflow',e.id,workPlanId,isPro)} ondblclick={()=> false}  
                                                            unselectable='off' contenteditable='false' style={{cursor:'pointer',textDecoration:'underline !important',marginRight:'8px'}}>{e.name} </a>
                                                        </div>
                                                    }):''
                                                }
                                                {
                                                    element.docids.length>0?
                                                    element.docids.map((e,_index)=>{//文档
                                                        return <div>
                                                            <span className="icon-blog-Document" style={{paddingRight:'5px'}}/>
                                                            <a href='javascript:void(0)'  linkid={e.id} linkType='workflow' 
                                                            onClick={()=> openWorkplanAppLink('doc',e.id,workPlanId,isPro)} ondblclick={()=> false}  
                                                            unselectable='off' contenteditable='false' style={{cursor:'pointer',textDecoration:'underline !important',marginRight:'8px'}}>{e.name} </a>
                                                        </div>
                                                    }):''
                                                }
                                            </Col>
                                        {/*</WeaNewScroll>*/}
                                    </Row>
                                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@8o3w88@edit`} style={{margin:'10px 0'}}>
                                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@h42ojc@edit`} span={8} offset={2}>
                                            {element.time}
                                        </Col>
                                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@2h0edk@edit`} span = {14}>
                                        {
                                            element.canedit ? (
                                                <span
                                                    className="wea-mbwcbr-item icon-coms-edit"
                                                    style = {{cursor:'pointer',position:'absolute',right:'90px',color: '#b2b2b2'}}
                                                    onClick={() => this.edit(element.id)}
                                                ><span style={{color: '#666666'}}>&nbsp;{getLabel(26473,'编辑')}</span></span>
                                            ) : ""
                                        }
                                        {
                                            element.canedit ? (
                                                <span
                                                    className="wea-mbwcbr-item icon-coms-delete"
                                                    onClick={() => this.delete(element.id)}
                                                    style = {{position:'absolute',right:'20px',cursor:'pointer', color: '#b2b2b2'}}
                                                ><span style={{color: '#666666'}}>&nbsp;{getLabel(91,'删除')}</span></span>
                                            ) : ""
                                        }
                                        </Col>
                                    </Row>
                                    
                                </div>  
                            return show
                        })
                    }
                    {
                        exchangeListDatas && exchangeListDatas.length == 1 ?
                        <div style={{textAlign:'center',height:'195px'}}>
                            <span className="icon-Meeting-Unhappy" style={{display:'inline-block',marginTop:'50px'}}><span style={{paddingLeft:'5px'}}>{getLabel(383567,'暂无相关交流')}</span></span> 
                        </div> 

                        :''
                    }
            </div>
        )
    }
    
    
    edit = (_id)=>{
      let {BrowserList} = this.state;
      BrowserList.datas.forEach((element,index)=>{
        if(_id == element['id']){
            element.isEdit = true;
            if(BrowserList[_id]==undefined){
                BrowserList[_id] = {};
            }
            BrowserList[_id].relatedwf = element.relatedwf;
            BrowserList[_id].docids = element.docids;
            BrowserList[_id].projectids = element.projectids;
            BrowserList[_id].relatedcus = element.relatedcus;
            BrowserList[_id].relateddoc = element.relateddoc;
        }
      });
      this.setState({BrowserList:BrowserList})
      

    }
    onChange = (id,text)=>{
        let {BrowserList} = this.state;
        let oldBrowserList = {...BrowserList};
        if(oldBrowserList[id]==undefined){
            oldBrowserList[id] = {};
        } else {
			!this.state.toolChange && Object.keys(oldBrowserList[id]).forEach(keys => {
				if(oldBrowserList[id][keys] && oldBrowserList[id][keys].length > 0) {
					let temp = [];
					Array.isArray(oldBrowserList[id][keys]) && oldBrowserList[id][keys].forEach(v => {
						if(keys === 'docids' ) {
						 	text.indexOf(`linktype="doc"`) > -1 && text.indexOf(`linkid="${v.id}"`) > -1 && temp.push(v);
						}else if(keys === 'projectids') {
							text.indexOf(`linktype="project"`) > -1 && text.indexOf(`linkid="${v.id}"`) > -1 && temp.push(v);
						}else if(keys === 'relatedcus' ) {
							text.indexOf(`linktype="crm"`) > -1 && text.indexOf(`linkid="${v.id}"`) > -1 && temp.push(v);
						}else if(keys === 'relatedprj' ) {
							text.indexOf(`linktype="task"`) > -1 && text.indexOf(`linkid="${v.id}"`) > -1 && temp.push(v);
						}else if(keys === 'relatedwf') {
							text.indexOf(`linktype="workflow"`) > -1 && text.indexOf(`linkid="${v.id}"`) > -1 && temp.push(v);
						}else if(keys === 'relateddoc') {
                            let tempIds = [];
							v.id && text.indexOf(`linktype="file"`) > -1 && Array.isArray(v.id) && v.id.forEach(res => {
								if(text.indexOf(`linkid="${res}"`) > -1) {
									tempIds.push(res);
								}
							}); 
							v.id = tempIds;
							temp.push(v);
							// v.id && text.indexOf(`linktype="file"`) > -1 && text.indexOf(`linkid="${v.id[0]}"`) > -1 && temp.push(v);
						}
					});
					oldBrowserList[id][keys] = temp;
				}
			});
		}
        oldBrowserList[id]['remark'] = text;
        this.setState({BrowserList:oldBrowserList})
    }
    delete = (e)=>{
        let params = {id:e}, _this = this; 
        confirm({
            title : getLabel(131329,'信息确认'),
            content : (<span>{getLabel(15097,'确定要删除吗？')}</span>),
            onOk(){
                WeaTools.callApi('/api/workplan/exchange/delete', 'POST', params).then(()=>{
                    _this.getExchangeList()//获取列表
                  })
            },
            onCancel() {}
        })
        

    }
    dosubmit = (id)=>{
        const {BrowserList} = this.state;
        let oldBrowserList = {...BrowserList}
        const {workPlanId,actions} = this.props;
        let params = oldBrowserList[id];
        if(!this.refs[`${id}_discuss`]) return;
        if(this.refs[`${id}_discuss`].wrappedInstance){
			params = {...params,remark: this.refs[`${id}_discuss`].wrappedInstance.getData()}
		}else {
			params = {...params,remark: this.refs[`${id}_discuss`].getData()}
		}
        let mewParams ={...params}
        let canSubmit = false;
        for(let key in mewParams){
            if(key != 'id' && key != 'workPlanId'){
                if(key == 'remark'){
                    if(mewParams[key]){
                        canSubmit = true 
                    }
                }
            }
        }

        if(params.docids.length == 0){
            delete mewParams.docids
        }
        if(params.projectids.length == 0){
            delete mewParams.projectids
        }
        if(params.relatedcus.length == 0){
            delete mewParams.relatedcus
        }
        if(params.relateddoc.length == 0){
            delete mewParams.relateddoc
        }
        if(params.relatedwf.length == 0){
            delete mewParams.relatedwf
        }
        if(params.docids.length > 0){
            let docidsarr = []
            params.docids.forEach((_e,_index)=>{
                docidsarr.push(_e['id']);
            })
            mewParams.docids = docidsarr.join(',');
        }
        if(params.projectids.length > 0){
            let projectidssarr = []
            params.projectids.forEach((_e,_index)=>{
                projectidssarr.push(_e['id']);
            })
            mewParams.projectids = projectidssarr.join(',');

        }
        if(params.relatedcus.length > 0){
            let relatedcusarr = []
            params.relatedcus.forEach((_e,_index)=>{
                relatedcusarr.push(_e['id']);
            })
            mewParams.relatedcus = relatedcusarr.join(',');

        }
        if(params.relateddoc.length > 0){
            let relateddocarr = []
            params.relateddoc.forEach((_e,_index)=>{
                _e['id'] ? relateddocarr.push(_e['id']) : relateddocarr.push(_e['fileid']);
            })
            mewParams.relateddoc = relateddocarr.join(',');

        }
        if(params.relatedwf.length > 0){
            let relatedwfarr = []
            params.relatedwf.forEach((_e,_index)=>{
                relatedwfarr.push(_e['id']);
            })
            mewParams.relatedwf = relatedwfarr.join(',');

        }
        mewParams['id'] = id=='create'?'':id;
        mewParams['workplanid'] = workPlanId;
        mewParams['isfromchatshare'] = this.props.isfromchatshare
        mewParams['sharer'] = this.props.sharer
        let stateBrowserList ={...BrowserList};
        stateBrowserList['create']['docids']=[]
        stateBrowserList['create']['projectids']=[]
        stateBrowserList['create']['relatedcus']=[]
        stateBrowserList['create']['relateddoc']=[]
        stateBrowserList['create']['relatedwf']=[]
        stateBrowserList['create']['remark']=''
        if(this.refs[`${id}_discuss`]){
          this.refs[`${id}_discuss`].pushAtMessage(()=>{
          })
        }
        if(canSubmit){
            this.setState({BrowserList:stateBrowserList});
            WeaTools.callApi('/api/workplan/exchange/save', 'POST', mewParams).then((result)=>{
              if(result.status == true){
                this.getExchangeList()//获取列表
              }
            })

        }else{
            Modal.warning({
                title: getLabel(127354,'警告'),
                content: getLabel(126982,'请填写内容'),
            });
        }


    }
    getExchangeList = ()=>{
      WeaTools.callApi('/api/workplan/exchange/getExchangeList', 'POST', {workplanid:this.props.workPlanId,isfromchatshare:this.props.isfromchatshare,sharer:this.props.sharer}).then((exchangeList)=>{
        exchangeList.datas.forEach((element,index)=>{
          element.isEdit = false
        })
        exchangeList.datas.unshift({
          id:'create',
          isEdit:true,
          remark:'',
          docids:[],
          projectids:[],
          relatedcus:[],
          relateddoc:[],
          relatedwf:[],
        })

        let BrowserList = {};
        exchangeList.datas.forEach((element,index)=>{
          if(BrowserList[element['id']]==undefined){
              BrowserList[element['id']] = {};
          }
          BrowserList[element['id']].remark = element.remark
          BrowserList[element['id']].docids = element.docids
          BrowserList[element['id']].projectids = element.projectids
          BrowserList[element['id']].relatedcus = element.relatedcus
          BrowserList[element['id']].relateddoc = element.relateddoc
          BrowserList[element['id']].relatedwf = element.relatedwf
        })
          BrowserList.datas = exchangeList.datas;
          BrowserList.docids = exchangeList.docids
          BrowserList.projectids = exchangeList.projectids
          BrowserList.relatedcus = exchangeList.relatedcus
          BrowserList.relateddoc = exchangeList.relateddoc
          BrowserList.relatedwf = exchangeList.relatedwf
          this.setState({BrowserList:BrowserList})

          let {setParam}= this.props.createWorkPlanStore;
          setParam({exchangeList: exchangeList});
      })
    }
    docancel = (e)=>{
      let {BrowserList} = this.state;
      BrowserList.datas.forEach((element,index)=>{
        if(e == index){
            element.isEdit = false;
        }
      })
      this.setState({BrowserList:BrowserList})
      
    }

    transfStr = (name = '', ids = '', list = [], type = '',id = '') => {
        this.setState({ toolChange: true });
        let {BrowserList} = this.state;
        let {workPlanId} = this.props;
        let {isPro}= this.props.createWorkPlanStore;
        let str = '';
        let idsArr = [];
        const mirror = {
            37: "doc",
            prjtsk: "task",
            18: "crm",
            152: "workflow",
            135: "project",
            workplan: "workplan",
            blogTemplate: "blogTemplate"
        }
        const browserType = {
            37: "docids",
            prjtsk: "relatedprj",
            18: "relatedcus",
            152: "relatedwf",
            135: "projectids",//项目
            Upload:"relateddoc",//附件
        }
        let oldBrowserList = { ...BrowserList };
		if (oldBrowserList[id] == undefined) {
			oldBrowserList[id] = {};
        }
        //判断所选中的id是否已记录
		let oldIds = [];
		if(name == 'Browser'){
			oldIds = oldBrowserList[id][browserType[type]].map(item =>{
				return item.id
			})
		}
        list.map(item => {
            if(name === 'Browser'){
                // let urlstr=this.getWorkplanAppLink(mirror[type],item.id,workPlanId);
                if(oldIds.indexOf(item.id) < 0){
                    str +=  `&nbsp;<a onclick='openWorkplanAppLink("${mirror[type]}",${item.id},${workPlanId},${isPro})' target='_blank' linkid='${item.id}' linkType='${mirror[type]}'  unselectable='off' contenteditable='false' style='cursor:pointer;text-decoration:underline !important;margin-right:8px'>${item.name || item.showname}</a>&nbsp;`
                    idsArr.push(item.id)
                }
            }
            if(name === 'Upload' && type === 'image'){
                str += '&nbsp;<img class="formImgPlay" src="' + item.imgSrc + '" onclick="ecCom.WeaRichText.playImg(this)" data-imgsrc="' + (item.imgSrc) + '" />&nbsp;'
            }
            if(name === 'Upload' && type === 'file'){
                str += `&nbsp;<a linkid="${item.fileid}" linktype="file" onclick='openWorkplanDiscussDoc(this,${item.fileid},${workPlanId})' unselectable='off' contenteditable='false' style='cursor:pointer;text-decoration:underline !important;margin-right:8px'>${item.filename}</a>&nbsp;`
            }
        })
        
        if(name!='Upload'){
            oldBrowserList[id][browserType[type]] = list;
        }else{
            oldBrowserList[id]['relateddoc'].push({id:ids})

        }
        this.setState({BrowserList:oldBrowserList}, () => {
			setTimeout(() => {
				this.setState({toolChange: false});
			}, 0);
		})
        return str
    }
}

//打开附件
window.openWorkplanDiscussDoc = (t, showid, workplanid) => {
  openFullWindowHaveBar(`/spa/document/index2file.jsp?id=${showid}&isOpenFirstAss=1&workplanid=${workplanid}`);
    }

window.openWorkplanAppLink = (linkType, linkid, workplanid, isPro=false) => {
  if (linkType == "doc"){
    window.open(`/spa/document/index.jsp?id=${linkid}&workplanid=${workplanid}`)
  }else if (linkType == "task"){
    window.open(`/spa/prj/index.html#/main/prj/taskCard?taskid=${linkid}`)
  }else if (linkType == "crm"){
    window.open(isPro?`/CRM/manage/customer/CustomerBaseView.jsp?CustomerID=${linkid}`:`/spa/crm/static/index.html#/main/crm/customerView?customerId=${linkid}`)
  }else if (linkType == "workflow"){
    window.open(`/spa/workflow/static4form/index.html#/main/workflow/req?fromModul=workplan&modulResourceId=${workplanid}&requestid=${linkid}`)
  }else if (linkType == "project"){
    window.open(`/spa/prj/index.html#/main/prj/projectCard?prjid=${linkid}`)
  }else {
    return false;
  }
}

export default TabDiscuss


